package middlewares

//sdfsdfdsf
import (
	"context"
	pb "kitest1"
	"time"

	"github.com/go-kit/kit/log"
)

type LogMiddle struct {
	pb.CalcServer
	logger log.Logger
}

func (s LogMiddle) Add(ctx context.Context, in *pb.CalcRequest) (ret *pb.CalcResponse, err error) {
	defer func(beign time.Time) {
		s.logger.Log(
			"function", "Add",
			"a", in.A,
			"b", in.B,
			"result", ret.Result,
			"took", time.Since(beign),
		)
	}(time.Now())

	ret, err = s.CalcServer.Add(ctx, in)
	return ret, err
}

func NewLogMiddle(next pb.CalcServer, log log.Logger) pb.CalcServer {
	return LogMiddle{next, log}
}
